using System;
using InfoJetSoft.Service.Worker;
using InfoJetSoft.Service.Util;

namespace InfoJetSoft.Service.ManagedCode
{
	/// <summary>
	/// Summary description for DAVAdapter.
	/// </summary>
	public class DAVAdapter : Microsoft.Office.Interop.InfoPath.SemiTrust.DAVAdapterObject
	{

		private InfoJetSoft.Service.Entity.Form form = null;
		private InfoJetSoft.Service.Entity.DataDavAdapter davAdapter = null;

		public DAVAdapter( InfoJetSoft.Service.Entity.Form frm, InfoJetSoft.Service.Entity.DataDavAdapter adapter )
		{
			this.form = frm;
			this.davAdapter = (InfoJetSoft.Service.Entity.DataDavAdapter)DataAdapterTableUtil.getCurrentAdapter( this.form, adapter );
		}

		public string Name 
		{ 
			get
			{
				return this.davAdapter.Name;
			}
		}


		public bool QueryAllowed 
		{ 
			get
			{
				return this.davAdapter.QueryAllowed;
			}
		}

		public bool SubmitAllowed 
		{ 
			get
			{
				return this.davAdapter.SubmitAllowed;
			}
		}

		public string FolderURL
		{ 
			get
			{
				return this.davAdapter.FolderURLValue;
			}
			set
			{
				this.davAdapter.FolderURLValue = value;
			}
		}

		public string FileName 
		{ 
			get
			{
				if( this.davAdapter.FileName == null )
				{
					return DataObjectDavSubmitWorker.getFileName( this.form, this.davAdapter );
				}
				else
				{
					return this.davAdapter.FileName;
				}
			}
			set
			{
				this.davAdapter.FileName = value;
			}
		}

		public void Submit()
        {
            //CID 0859 //2012.03.19 //Begin
            int errorCount = FormIsValidateWorker.Validate(form);
            if (errorCount > 0)
            {
                throw new InfoJetException(MessageUtil.FormContainsValidationErrors(), null);
            }
            //CID 0859 //2012.03.19 //End
			DataObjectDavSubmitWorker.submitDoc( this.form, this.davAdapter );
		}
		
		//Unsupported
		public void Query(){}
		public void SubmitData(Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode pData){}

	}
}
